Welcome to overview of node package manager. After watching this video, you will be able
to explain the purpose of a package manager, describe the two main aspects of node package
manager (NPM), describe the purpose of a package.json file, and compare and contrast a local NPM install
to a global NPM install When dealing with languages that use modules
and packages, such as JavaScript, a tool called a package manager is usually needed. A package manager is a set of tools used to
deal with modules and packages containing dependencies. Sometimes it is also referred to as a package-management
system. Dependencies are code, usually in the form
of libraries and packages, that are called and reused in a program. So, for example, say you are developing a
new module, and you call a function contained in another module written by you, which calls
another module written by someone else, which calls yet another module, written by that
3rd-party. The module you are writing is “dependent”
on all of those other modules. A library of code usually contains many dependencies,
but the library is self-contained and isn’t dependent on code outside of the library itself. Packages work the same. A package manager automates the process of
finding, installing, upgrading, configuring, maintaining, and removing packages for a computer
program. Package managers usually are connected to
and maintain a database of dependencies and versioning information for the packages in
a repository. The package manager ensures that a piece of
software has the dependencies to run correctly and eliminates the need to do this work manually. Node Package Manager, usually abbreviated
as NPM, is the default package manager for the Node.js runtime engine. NPM has two functions. First, it provides a command line interface
that allows users to publish and download packages. Second, it behaves as an online repository
of binary JavaScript packages. The repository is a database of packages that
tracks versions of packages referenced in applications. All NPM packages require a file named “package.json”
that should be located in the project’s root directory. NPM uses the metadata in the package.json
file to determine all of the dependencies in a package. This file contains the project’s identifying
metadata in the form of key-value pairs that, at a minimum, identify the name of the project
and the project’s version number. The code shown here displays an example of
those two key-value pairs. There are two ways in which NPM can install
packages: locally or globally. You will want to use the local install if
you are installing a package you want to use within your application. Run the local install command from the directory
you want the package installed in. The local install is npm’s default behavior. To install the node_modules package locally,
use the NPM command line interface to enter: npm install <package_name> This command creates a directory named node_modules
with the package and its dependencies in your current working directory. Packages can also be installed globally. A global install means that all applications
on the machine in which the package is installed can use that code. Global installs should be used judiciously
because all projects on that computer will make use of that package and its dependencies. If you have different versions of a project
on your machine, they will all use the globally installed package, which might break compatibility
with other dependencies. To install node_modules so the package
can be accessed by any application on the machine, which means they are installed globally,
use the command “npm install minus g package_name” in
the command line interface. It is the same command as the local install
command but adds the minus g option. In this video, you learned that: The package manager ensures a piece of software
has the dependencies it needs to run correctly. NPM provides a command line interface tool
and also functions as an online database of JavaScript packages. NPM uses the metadata in a package.json file
to determine a package’s dependencies. And, a local install means only the application
within the directory of the installed can access the package, whereas a global install
means that any application on the machine can access the package.